<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>step 2</title>
</head>

<body>
    <div id="wp"></div>
    <script id="tpl" type="text/html">
        <p>[str]</p>
        <p>[str1]</p>
    </script>
    <script>
        const reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
        const obj = {
            'str': 'hello world',
            'str1': 'hello world 1'
        }
        const html = document.getElementById('tpl').innerHTML;
        const tpl = html.replace(reg, (node, key) => {
            return obj[key];
        });
        document.getElementById('wp').innerHTML = tpl;
    </script>
</body>

</html>